package es.aa.android.cartomatic.domain;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.ByteArrayOutputStream;
import java.io.Serializable;

public class Entity implements Serializable {

    private static final long serialVersionUID = 1L;
    private int id;
    private String name;
    private String description;
    private transient Bitmap image;
    byte[] imageArray;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Bitmap getImage() {
        if (image == null) {
            BitmapFactory.Options options = new BitmapFactory.Options();
            image = BitmapFactory.decodeByteArray(imageArray, 0, imageArray.length, options);
        }
        return image;
    }

    public void setImage(Bitmap image) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        image.compress(Bitmap.CompressFormat.JPEG, 50, stream);
        this.imageArray = stream.toByteArray();
        this.image = image;
    }

    public byte[] getImageArray() {
        return imageArray;
    }

}
